package com.sam.spring.test.robot;

import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.CannotGetJdbcConnectionException;

public class App {
	
	public static void main(String[] args) {
		ApplicationContext context = new ClassPathXmlApplicationContext("/com/sam/spring/test/beans/jdbc_bean.xml");
		
		OffersDAO offersDao = (OffersDAO)context.getBean("offersDao");
		
		try {
			List<Offer> offers = offersDao.getOffers();
			for(Offer offer: offers){
				System.out.println(offer);
			}
			Offer offer = offersDao.getOffer(2);
			System.out.println("it must be mike "+ offer);
			
		    offersDao.delete(3);
			
		} catch (CannotGetJdbcConnectionException e) {
			// TODO: handle exception
			System.out.println("Cannot get database connection");
			
		} catch (DataAccessException e) {
			// TODO: handle exception
			System.out.println(e.getMessage());
			System.out.println(e.getClass());
		}
		((ClassPathXmlApplicationContext)context).close();
	}

}
